package com.zero.xiaodai.utils;




import net.dongliu.apk.parser.ApkFile;
import net.dongliu.apk.parser.bean.ApkMeta;
import net.dongliu.apk.parser.bean.UseFeature;

import java.io.*;
import java.nio.charset.Charset;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

public class APkXml {

	
	
	
    public static Map<String,Object> getManifestXml(File file) {
    	Map<String,Object> map=new HashMap<>();
        try{

            // apk�ļ���ַ����������λ�ã�
            //String apkFileURL = Main.class.getResource("ofoScanner_24_V1.5.7.apk").getPath();
            //String apkFileURL1 = "X:\\ofoScanner_24_V1.5.7.apk";
            // apk�е�AndroidManifest.xml����� ����ר�ŵĸ�ʽ������ֱ��ͨ����ͨ��dom�������ж�ȡ��
            // ��Ҫͨ���ٷ�����ĸ�ʽ��׼���ֶζ�ȡ����ֽ�����
            // ���õ����� ��װ jar ʵ�ֶԱ�����AndroidManifest.xml�ļ���ȡ

            // apk ��Ϣ
            try (ApkFile apkFile = new ApkFile(file)) {
                ApkMeta apkMeta = apkFile.getApkMeta();
                
                System.out.println(apkMeta.getLabel());
                System.out.println(apkMeta.getPackageName());
                System.out.println(apkMeta.getVersionCode());
                System.out.println(apkMeta.getIcon());
                map.put("icon", apkMeta.getIcon());
                map.put("versionCode",apkMeta.getVersionCode());
                System.out.println(apkMeta.getMaxSdkVersion());
                System.out.println(apkMeta.getMinSdkVersion());
                System.out.println(apkMeta.getTargetSdkVersion());
                System.out.println(apkMeta.getName());

                System.out.println("===========================================");
                for (UseFeature feature : apkMeta.getUsesFeatures()) {
                    System.out.println(feature.getName());
                }
            }

            // apk AndroidManifest.xml
            try (ApkFile apkFile = new ApkFile(file)) {
                String xml = apkFile.getManifestXml();
                
                System.out.println(xml);
            }

        }catch (IOException e){
            e.printStackTrace();
        }
        
        return map;
        
        
    }
}
